<template>
	<footer class="footer">
		<span class="todo-count">剩余<strong>{{leftCount}}</strong></span>
		<ul class="filters">
			<li>
				<a @click="changeType('all')" :class="{selected:selectType==='all'}" href="javascript:;">全部</a>
			</li>
			<li>
				<a @click="changeType('active')" :class="{selected:selectType==='active'}" href="javascript:;">未完成</a>
			</li>
			<li>
				<a @click="changeType('complete')" :class="{selected:selectType==='complete'}" href="javascript:;">已完成</a>
			</li>
		</ul>
		<button @click="del" v-show="showClear" class="clear-completed">清除已完成</button>
	</footer>
</template>

<script>
	export default {
		data(){
			return{
				selectType:'all'
			}
		},
		props:{
			arr:{
				type:Array,
				required:true,
			}
		},
		computed:{
			leftCount(){
				return this.arr.filter(item=>!item.isDone).length
			},
			showClear(){
				return this.arr.some(item=>item.isDone)
			}
		},
		methods:{
			del(){
				this.$emit('clearDone')
			}
		},
		changeType(type){
			this.selectType=type
			this.$emit('changeType',type)
		}
	}
</script>
